package com.terrynoya.fight.stateMachine.triggers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.emuns.Axis;
	import com.terrynoya.fight.emuns.Facing;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.evaluation.ParseState;

	public class P2Dist
	{
		public function P2Dist()
		{
		}
		
		public static function eval(data:Object,node:Node):*
		{
			var chara:Character = Character(data);
			if(chara == null)
			{
				return 0;
			}
			var opponent:Character = chara.getOpponent();
			if(opponent == null)
			{
				return 0;
			}
			
			var axis:int = node.arguments[0];
			switch(axis)
			{
				case Axis.X:
				{
					var distance:Number = Math.abs(chara.position.x - opponent.position.x);
					if(chara.currentFacing == Facing.RIGHT)
					{
						return (opponent.position.x >= chara.position.x) ? distance : -distance;
					}
					else
					{
						return (opponent.position.x >= chara.position.x) ? -distance : distance;
					}
					break;	
				}
			}
		}
		
		public static function parse(state:ParseState):Node
		{
			return state.baseNode;
		}
	}
}